package demo1;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //长度为k的子数组的能量值 1
    public int[] resultsArray(int[] nums, int k) {
        if (k == 1) {
            return nums;
        }
        int n = nums.length;
        int[] ret = new int[n-k+1];
        for (int i = 0; i <= n-k; i++) {
            int j=0;
            for (j = i; j < k+i-1; j++) {
                if(nums[j]!=nums[j+1]-1){
                    ret[i] = -1;
                    break;
                }
            }
            if(j==k+i-1) {
                ret[i] = nums[i+k-1];
            }
        }
        return ret;
    }
}


